package team.unstudio.unknownrpg_base.attribute.quality;

import indi.defoliation.unknownrpg.api.RPGItem;
import indi.defoliation.unknownrpg.api.attribute.Attribute;
import indi.defoliation.unknownrpg.api.attribute.NumberAttribute;

public class QualityManager {

	private static QualityFile FILE;

	@SuppressWarnings("unchecked")
	public static String getQuality(RPGItem item) {
		int score = 0;
		for(Attribute att : item.getAttributes()) {
			if(att instanceof NumberAttribute<?>) {
				score += ((NumberAttribute<Number>)att)
						.get().intValue()*FILE.getAttributeScore(att.getKeyName());
			}else
				score+=FILE.getAttributeScore(att.getKeyName());
		}
		String quality = "default";
		for(String q : FILE.getQualities()) {
			int value = FILE.getQualityScore(q);
			if(score>value&&FILE.getQualityScore(q)<value)
				quality=q;
		}
		return quality;
	}

	public static void setQualityFile(QualityFile file) {
		FILE = file;
	}

}
